<?php

namespace Biz\model\settlement;

use Doraemon\pockets\datebase\BaseDbModel;

class BillOperateLog extends BaseDbModel
{

    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_settlement';

    const _DATABASE_ = 'shop_settlement';

    const _TABLE_NAME = 'bill_operate_log';

    const TYPE_OPERATE_CREATE = 1;//创建账单
    const TYPE_OPERATE_COMMISSION_ADJUSTMENT = 2;//运营调整-调整佣金
    const TYPE_OPERATE_CONFIRM_BILL = 3;//商家确认账单
    const TYPE_OPERATE_TRANSFER_AMOUNT = 4;//财务确认转账
    const TYPE_OPERATE_TRANSFER_DEPOSIT_ADD = 5;//保证金补货款
    const TYPE_OPERATE_HHZ_ALLOWANCE_ADJUSTMENT = 6;//调整平台补贴-调整平台补贴

    const USER_OPERATE_SYS = 0;//sys系统
    const USER_OPERATE_ADMIN = 1;//好好住管理员
    const USER_OPERATE_SHOP = 2;//店铺

    public static $operateTypeDesc = [
        self::TYPE_OPERATE_CREATE => '创建账单',
        self::TYPE_OPERATE_COMMISSION_ADJUSTMENT => '运营调整-调整佣金',
        self::TYPE_OPERATE_CONFIRM_BILL => '商家确认账单',
        self::TYPE_OPERATE_TRANSFER_AMOUNT => '管理员确认转账',
        self::TYPE_OPERATE_TRANSFER_DEPOSIT_ADD => '保证金补货款',
        self::TYPE_OPERATE_HHZ_ALLOWANCE_ADJUSTMENT => '运营调整-调整平台补贴',
    ];

    public static function addData($data)
    {
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            throw new \Exception('数据库操作错误');
        }
        return true;
    }

    /**
     * 查询是否调整过账单
     * @param $billId
     * @param $shopId
     * @param $billDate
     * @param $operateType
     * @return mixed
     */
    public static function hasOperateBill($billId, $shopId, $billDate, $operateType)
    {
        return self::has(['bill_id' => $billId, 'shop_id' => $shopId, 'bill_date' => $billDate, 'operate_type' => $operateType]);
    }

}

